package com.wl2o2o.writtenview.mt;


import java.util.Scanner;

/**
 * @Author <a href="https://github.com/wl2o2o">程序员CSGUIDER</a>
 * @From <a href="https://wl2o2o.github.io">CSGUIDER博客</a>
 * @CreateTime 2024/3/16
 */

public class Main1 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String word = in.next();
        System.out.println(method(word));
    }
    public static int method(String word) {
        int cntLower = 0, cntUp = 0, index = 0;
        for (int i = 0; i < word.length(); i++) {
            char c = word.charAt(i);
            if (i == 0) {
                index = Character.isUpperCase(c) ? 1 : 0;
                continue;
            }
            if (i == 1 && index == 1 && Character.isLowerCase(c)) {
                cntUp ++;
            } else if ((i ==1 && index == 0) || (i > 1)) {
                if (Character.isUpperCase(c)) {
                    cntUp++;
                } else if (index ==1 && Character.isLowerCase(c)) {
                    cntLower++;
                }
            }

        }

        if (index == 0) {
            cntUp += cntLower;
            cntLower = 0;
        }
        return Math.min(cntLower, cntUp);

    }
}
